//
//  Second1ViewController.m
//  UI_豆瓣影院
//
//  Created by dllo on 16/1/9.
//  Copyright © 2016年 dllo. All rights reserved.
//

#import "Second1ViewController.h"
#import "UIImageView+WebCache.h"
#import "AAALHXDateHandle.h"
#import "WEBViewController.h"
@interface Second1ViewController ()

@end

@implementation Second1ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.view.backgroundColor = [UIColor whiteColor];
    UIButton * button = [UIButton buttonWithType:UIButtonTypeCustom];
    [button setTitle:@"播放" forState:UIControlStateNormal];
    [button setTitleColor:[UIColor redColor] forState:UIControlStateNormal];
    button.frame = CGRectMake(20, 10, 40, 40);
    button.backgroundColor = [UIColor cyanColor];
    [self.view addSubview:button];
    [button addTarget:self action:@selector(buttonAction:) forControlEvents:UIControlEventTouchUpInside];
    
    
    self.view.backgroundColor = [UIColor whiteColor];
    UIBarButtonItem *item = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"iconfont-share.png"] style:UIBarButtonItemStylePlain target:self action:@selector(itemAction)];
    self.navigationItem.rightBarButtonItem = item;
   
    UIImageView *imageview = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 300, 350)];
    imageview.center = self.view.center;
    NSString *str = _model.image;
    NSURL *url = [NSURL URLWithString:str];
    [imageview sd_setImageWithURL:url];
    [self.view addSubview:imageview];
    [imageview release];
    
    UILabel *lable = [[UILabel alloc] initWithFrame:CGRectMake(0, 70, 375, 50)];
    lable.textAlignment = NSTextAlignmentCenter;
    lable.font = [UIFont boldSystemFontOfSize:23];
    lable.text = _model.title;
    lable.backgroundColor = [UIColor purpleColor];
    [self.view addSubview:lable];
}

- (void)buttonAction:(UIButton *)button {
    WEBViewController *vc = [[WEBViewController alloc] init];
   
    [self.navigationController pushViewController:vc animated:YES];
    
    
}

- (void)itemAction {
   
    // 查询返回的数组
    self.array = [[AAALHXDateHandle sharedDateBaseHandle] selectTable1];
  
    // 判断是否包含
    if ([_array containsObject:_model.title]) {
        UIAlertController *hadCollectAlert = [UIAlertController alertControllerWithTitle:@"收藏提示" message:@"该活动已经被收藏过" preferredStyle:(UIAlertControllerStyleAlert)];
        [self presentViewController:hadCollectAlert animated:YES completion:nil];
        [self dismissViewControllerAnimated:YES completion:nil];
    } else {
       
        if (![_array containsObject:_model.title]) {
            [[AAALHXDateHandle sharedDateBaseHandle] insertModel1:_model];
             UIAlertController *collectAlert = [UIAlertController alertControllerWithTitle:@"收藏提示" message:@"收藏成功" preferredStyle:(UIAlertControllerStyleAlert)];
            [self presentViewController:collectAlert animated:YES completion:nil];
            [self dismissViewControllerAnimated:YES completion:nil];
        }
        
    }

    
    
    
    
}




- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
